package edu.pku.sei.autounit.generator;

import java.util.Map;

import edu.pku.sei.autounit.core.Variable;
import edu.pku.sei.autounit.core.VariableFactory;
import edu.pku.sei.autounit.core.VariableGenerator;
import edu.pku.sei.autounit.filter.Filter;
import edu.pku.sei.autounit.reflect.Enum;
import edu.pku.sei.autounit.reflect.Type;
import edu.pku.sei.autounit.util.NameFactory;
import edu.pku.sei.autounit.util.Statements;

public class EnumGenerator implements VariableGenerator{

	static class EnumVariable implements Variable{

		private Type e;
		private String c;
		private String typeName;
		protected EnumVariable(Type e,String c){
			this.e = e;
			this.c = c;
		}
		
		public Statements getInitCode(Map<String, String> map) {
			typeName = e.getName(map);
			return new Statements();
		}

		
		public Type getType() {
			return e;
		}

		
		public String getValue() {
			return typeName+"."+c;
		}
		
	}
	
	public Variable generate(Type type, String name, VariableFactory vf,
			NameFactory nf) {
		if(type instanceof Enum){
			String []cs = ((Enum) type).getEnumConstants();
			int index = (int)(Math.random()*(cs.length-1));
			if(index>=0)
				return new EnumVariable(type,cs[index]);
		}
		return null;
	}

	
	public Variable generate(Type type, String name, Filter fliter,
			VariableFactory vf, NameFactory nf) {
		// TODO Auto-generated method stub
		return null;
	}

}
